package com.github.data_manage.config

import com.github.data_manage.controller.websocket.FundImportStatusHandler
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.socket.WebSocketHandler
import org.springframework.web.socket.config.annotation.EnableWebSocket
import org.springframework.web.socket.config.annotation.WebSocketConfigurer
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
import org.springframework.web.socket.server.standard.ServerEndpointExporter

/**
 * @author chenhainan
 * @since 2024-09-01 10:19
 */
@Configuration
@EnableWebSocket
class WebSocketConfig(
    private val fundImportStatusHandler: FundImportStatusHandler
): WebSocketConfigurer {

    @Bean
    fun serverEndpointExporter(): ServerEndpointExporter{
        return ServerEndpointExporter()
    }

    override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) {
        registry.addHandler(fundImportStatusHandler, "/fundImportStatus")
            .setAllowedOrigins("*")
    }

}